package main

import (
	"bufio"
	"fmt"
	"net"
	"os"
	"strings"
)

// client
func main() {
	conn, err := net.Dial("tcp", "localhost:8888")
	if err != nil {
		fmt.Println(err)
		return
	}

	// send message
	reader := bufio.NewReader(os.Stdin)
	for {
		line, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println(err)
		}
		line = strings.TrimSpace(line)
		if line == "exit" {
			fmt.Println(conn.LocalAddr().String(), "exit program")
			conn.Close()
			break
		}
		if _, err := conn.Write([]byte(line)); err != nil {
			fmt.Println("client err", err)
		}

	}
}
